package com.bingo.controller;

import com.bingo.common.R;
import com.bingo.entity.HisPool;
import com.bingo.entity.dto.everyDayForm.EveryDayFeedLoss;
import com.bingo.entity.dto.req.ReqFeedLossReport;
import com.bingo.entity.dto.req.ReqForm;
import com.bingo.entity.dto.req.ReqFormSite;
import com.bingo.service.FeedLossService;
import com.bingo.service.HisPoolService;
import com.bingo.until.IsToday;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/feedLoss")
public class FeedLossController {
    private FeedLossService feedLossService;
    @Autowired
    public void setFeedLossService(FeedLossService feedLossService) {
        this.feedLossService = feedLossService;
    }

    private HisPoolService hisPoolService;
    @Autowired
    public void setHisPoolService(HisPoolService hisPoolService) {
        this.hisPoolService = hisPoolService;
    }
    @PostMapping("/report")
    public R feedLoss(@RequestBody ReqFeedLossReport reqFeedLossReport) {
        if (!IsToday.isToday(reqFeedLossReport.getDate())){
            HisPool pool = hisPoolService.getPoolByNo(reqFeedLossReport.getPoolNo());
            if (pool == null || pool.getType() == 0){
                return R.error("不存在该池塘或为空塘!");
            }
        }
        return feedLossService.add(reqFeedLossReport.getPoolNo(), reqFeedLossReport.getFeed(), reqFeedLossReport.getLoss(), reqFeedLossReport.getLossWeight(),reqFeedLossReport.getDate(), reqFeedLossReport.getUserId());
    }

    @PostMapping
    public R everyDayFeedLoss(@RequestBody ReqForm reqForm) {
        List<EveryDayFeedLoss> everyDayFeedLoss = feedLossService.selectEveryDayFeedLoss(reqForm.getPoolNos(), reqForm.getDate()[0], reqForm.getDate()[1]);
        return R.success(everyDayFeedLoss);
    }


    @PostMapping("/site")
    public R siteFeedLoss(@RequestBody ReqFormSite reqFormSite) {
        return R.success(feedLossService.selectSiteFeedLoss(reqFormSite.getSiteNos(), reqFormSite.getDate()[0], reqFormSite.getDate()[1]));
    }

    @PostMapping("/record")
    public R feedLossRecord(@RequestBody ReqForm reqForm) {
        return R.success(feedLossService.selectFeedLossRecord(reqForm.getPoolNos(), reqForm.getDate()[0], reqForm.getDate()[1],reqForm.getUserId()));
    }


}
